package com.dream.inspect.modules.app.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dream.inspect.common.utils.R;
import com.dream.inspect.modules.app.constants.AttrConstants;
import com.dream.inspect.modules.business.entity.InstructionsEntity;
import com.dream.inspect.modules.business.entity.SuperviseProjectEntity;
import com.dream.inspect.modules.business.entity.SuperviseQuestionEntity;
import com.dream.inspect.modules.business.entity.SuperviseQuestionModifyEntity;
import com.dream.inspect.modules.business.entity.SuperviseRecordEntity;
import com.dream.inspect.modules.business.entity.SysXzqhEntity;
import com.dream.inspect.modules.business.service.HomeStatisticsService;
import com.dream.inspect.modules.business.service.InstructionsService;
import com.dream.inspect.modules.business.service.SuperviseProjectService;
import com.dream.inspect.modules.business.service.SuperviseQuestionModifyService;
import com.dream.inspect.modules.business.service.SuperviseQuestionService;
import com.dream.inspect.modules.business.service.SuperviseRecordService;
import com.dream.inspect.modules.business.service.SysXzqhService;

/**
 * app首页
 */


@Controller
@RequestMapping("/app/home")
public class HomeController {

    @Autowired
    SuperviseProjectService superviseProjectService;
    @Autowired
    SuperviseRecordService superviseRecordService;
    @Autowired
    SuperviseQuestionService superviseQuestionService;
    @Autowired
    InstructionsService instructionsService;
    @Autowired
    SuperviseQuestionModifyService superviseQuestionModifyService;
    @Autowired
    private HomeStatisticsService homeStatisticsService;
    @Autowired
    private SysXzqhService sysXzqhService;

    /**
     * 行政区划列表
     */
    @ResponseBody
    @RequestMapping("/zoningList")
    public R zoningList(){
        List<SysXzqhEntity> list= sysXzqhService.findProvincesAndCities();

        return R.ok().put("data",list);
    }
	/**
     * 首页的待办专项统计(本月一览)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/todoProjectCount")
    public R todoProjectCount(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = superviseProjectService.selectThisMonthCount(params);
       
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }
    
	/**
     * 首页的督察录入统计(本月一览)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/superviseAddCount")
    public R superviseAddCount(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = superviseRecordService.selectThisMonthCount(params);
       
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }

	/**
     * 首页的督察问题统计(本月一览)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/superviseQuestionCount")
    public R superviseQuestionCount(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = superviseQuestionService.selectThisMonthCount(params);
       
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }

	/**
     * 首页的督察指令统计(本月一览)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/instructionsCount")
    public R instructionsCount(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = instructionsService.selectThisMonthCount(params);
       
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }
    
	/**
     * 首页的督察整改统计(本月一览)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/superviseQuestionModifyCount")
    public R superviseQuestionModifyCount(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = superviseQuestionModifyService.selectThisMonthCount(params);
       
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }
    /**
     * 区划问题整改统计
     *
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("findZoningQuestionStatistics")
    public R findZoningQuestionStatisticsForApp(@RequestParam Map<String, Object> params){

        return  R.ok().put("list",homeStatisticsService.findZoningQuestionStatisticsForApp(params));
    }
    /**
     * 问题统计 环形图
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("problemChartAnnular")
    public R problemChartAnnular(@RequestParam Map<String, Object> params){

        return R.ok().put("list",homeStatisticsService.problemChartAnnular(params));
    }
    
    /**
     * 全文查询(指令)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeInstructions")
    public R searchLikeInstructions(@RequestParam Map<String, String> params){
        int countNum = 0;
        
        List<InstructionsEntity> dataList = new ArrayList<InstructionsEntity>();
        countNum = instructionsService.findInstructionsForSearchPageCount(params);
        if (countNum != 0) {
            dataList = instructionsService.findInstructionsForSearchPage(params);
        }
        return R.ok().put(AttrConstants.DATA, dataList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 全文查询(专项查询)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeSuperviseProject")
    public R searchLikeSuperviseProject(@RequestParam Map<String, String> params){
        return R.ok().put(AttrConstants.DATA, superviseProjectService.findSuperviseProjectForSearchPage(params));
    }
    
    /**
     * 全文查询(督促记录查询)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeSuperviseRecord")
    public R searchLikeSuperviseRecord(@RequestParam Map<String, String> params){
        return R.ok().put(AttrConstants.DATA, superviseRecordService.findSuperviseRecordForSearchPage(params));
    }
    
    /**
     * 全文查询(督促问题查询)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeSuperviseQuestion")
    public R searchLikeSuperviseQuestion(@RequestParam Map<String, String> params){
        return R.ok().put(AttrConstants.DATA, superviseQuestionService.findSuperviseQuestionForSearchPage(params));
    }
    
    /**
     * 全文查询(整改历史查询)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeSuperviseQuestionModify")
    public R searchLikeSuperviseQuestionModify(@RequestParam Map<String, String> params){
        return R.ok().put(AttrConstants.DATA, superviseQuestionModifyService.findSuperviseQuestionMForSearchPage(params));
    }
    
    /**
     * 全文查询(整改历史查询)
     * 
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/searchLikeAll")
    public R searchLikeAll(@RequestParam Map<String, String> params){
    	 int countNum = 0;
         
         List<SuperviseProjectEntity> dataList = new ArrayList<SuperviseProjectEntity>();
         countNum = superviseProjectService.findAllForSearchPageCount(params);
         if (countNum != 0) {
             dataList = superviseProjectService.findAllForSearchPage(params);
         }
         return R.ok().put(AttrConstants.DATA, dataList).put(AttrConstants.COUNT_NUM, countNum);
    }
}
